from wtforms import TextAreaField, SelectField
from wtforms.validators import Email


def get_smtp_form():
    """
    获得smtp设置表单
    :return:
    """
    from flask_wtf import FlaskForm
    from wtforms import StringField, PasswordField, SubmitField
    from wtforms.validators import DataRequired, EqualTo, Length

    class Smtp(FlaskForm):
        host = StringField(label='主机Host', validators=[DataRequired()],
                           render_kw={
                               'value': '',
                               "class": "form-control"
                           }
                           )
        port = StringField(label='端口Port', validators=[DataRequired()],
                           render_kw={
                               'value': '465',
                               "class": "form-control"
                           }
                           )

        email = StringField(label='邮箱',
                            validators=[DataRequired(), Email(message=u'请输入有效的邮箱地址，比如：username@domain.com')],
                            render_kw={
                                'value': '',
                                "class": "form-control"
                            }
                            )

        password = PasswordField(label='密码',
                                 validators=[DataRequired(), Length(3, 8, '密码长度必须在3-8之间')],
                                 render_kw={
                                     'value': '',
                                     "class": "form-control"
                                 }
                                 )
        active = SelectField(label='激活',
                             validators=[DataRequired()],
                             render_kw={
                                 'value': '1',
                                 "class": "form-control"
                             },
                             choices=[(1, '激活'), (2, '不激活')],
                             default=1,
                             coerce=int
                             )
        submit = SubmitField(render_kw={
            'value': '设置 Smtp 信息',
            "class": "form-control"
        })

    return Smtp()


def get_email_template_form():
    """
    获得邮件模板表单
    :return:
    """
    from flask_wtf import FlaskForm
    from wtforms import StringField, PasswordField, SubmitField
    from wtforms.validators import DataRequired, EqualTo, Length

    class EmailTemplate(FlaskForm):
        id = StringField(label='ID',
                              validators=[],
                              render_kw={
                                  'type': 'hidden',
                                  'value': '',
                                  'class': 'input_text'
                              })
        subject = StringField(label='邮件主题',
                              validators=[DataRequired()],
                              render_kw={
                                  'value': '',
                                  'class': 'input_text'
                              })
        sender_nickname = StringField(label='发送者昵称', validators=[DataRequired()],
                                      render_kw={
                                          'value': '',
                                          "class": "form-control"
                                      }
                                      )
        content = TextAreaField(label='发送内容', validators=[DataRequired(), Email()],
                                render_kw={
                                    'value': '',
                                    "class": "form-control"
                                }
                                )

        active = SelectField(label='激活',
                             validators=[DataRequired()],
                             render_kw={
                                 'value': '1',
                                 "class": "form-control"
                             },
                             choices=[(1, '激活'), (2, '不激活')],
                             default=1,
                             coerce=int
                             )
        submit = SubmitField(render_kw={
            'value': '提交邮件模板',
            "class": "form-control"
        })

    return EmailTemplate()
